/*
 * @Descripttion:
 * @version:
 * @Author: ChenXiang
 * @Date: 2021-03-22 16:18:10
 * @LastEditors: ChenXiang
 * @LastEditTime: 2021-03-25 14:21:31
 */
export default {
  // 在等待一定时间后调用提供的函数（单位毫秒）？
  delay: (fn, wait, ...args) => setTimeout(fn, wait, ...args),

  // delay(function(text) {
  //     console.log(text);
  // }, 1000, "later"); // 一秒后记录 "later"

  // 在给定元素上触发特定事件，且可选传递自定义数据？

  triggerEvent: (el, eventType, detail) =>
    el.dispatchEvent(new CustomEvent(eventType, { detail })),

  // Examples
  // triggerEvent(document.getElementById("myId"), "click");
  // triggerEvent(document.getElementById( myId ), "click", { username: "bob" });

  // 移除一个元素的事件侦听器？
  off: (el, evt, fn, opts = false) => el.removeEventListener(evt, fn, opts)
  // const fn = () => console.log("!");
  // document.body.addEventListener("click", fn);
  // off(document.body, "click", fn); // no longer logs "!" upon clicking on the page
};
